package com.supcalls.parallel;

import java.util.Arrays;
import java.util.List;

public class ParallelStreamExample {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        // 串行流
        long startTime = System.nanoTime();
        numbers.stream().map(n -> n * 2).forEach(System.out::println);
        long serialTime = System.nanoTime() - startTime;

        // 并行流
        startTime = System.nanoTime();
        numbers.parallelStream().map(n -> n * 2).forEach(System.out::println);
        long parallelTime = System.nanoTime() - startTime;

        System.out.println("串行流耗时：" + serialTime);
        System.out.println("并行流耗时：" + parallelTime);
    }
}

